Hệ thống quản lý bệnh viện bằng C# với mã nguồn

1 using System;
2 using
System.Collections.Generic;
3 using
System.ComponentModel;
4 using
System.Data;
5 using
System.Drawing;
6 using
System.Linq;
7 using
System.Text;
8 using
System.Threading.Tasks;
9 using
System.Windows.Forms;
10 using
System.Data.SqlClient;
11
12 namespace
HospitalManagementSystemCSharp
13 {
14     
public partial class PatientInformation : Form
15     {
16         
public PatientInformation()
17         {
18             InitializeComponent();
19         }
20
21         
private void PatientInformation_Load(object sender, EventArgs e)
22         {
23             
// TODO: This line of code loads data into the 'hospitalDataSet1.patient' table. You can move, or remove it, as needed.
24             
this.patientTableAdapter.Fill(this.hospitalDataSet1.patient);
25             
using (SqlConnection con1 = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=F:\Sem.4\C# Projects\Trials\HospitalManagementSystemCSharp\HospitalManagementSystemCSharp\hospital.mdf;Integrated Security=True"))
26             {
27
28                 
string str2 = "SELECT * FROM patient";
29                 SqlCommand cmd2 =
new SqlCommand(str2, con1);
30                 SqlDataAdapter da =
new SqlDataAdapter(cmd2);
31                 DataTable dt =
new DataTable();
32                 da.Fill(dt);
33                 dataGridView1.DataSource =
new BindingSource(dt, null);
34             }
35         }
36
37         
private void button1_Click(object sender, EventArgs e)
38         {
39             SqlConnection con =
new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=F:\Sem.4\C# Projects\Trials\HospitalManagementSystemCSharp\HospitalManagementSystemCSharp\hospital.mdf;Integrated Security=True");
40
41             con.Open();
42             
if (textBox1.Text != "")
43             {
44                 
try
45                 {
46                     
string getCust = "select name,gen,age,date,cont,addr,disease,status,r_type,building,r_no,price from patient where id=" + Convert.ToInt32(textBox1.Text) + " ;";
47
48                     SqlCommand cmd =
new SqlCommand(getCust, con);
49                     SqlDataReader dr;
50                     dr = cmd.ExecuteReader();
51                     
if (dr.Read())
52                     {
53                         textBox2.Text = dr.GetValue(
0).ToString();
54                         
if (dr[1].ToString() == "Male")
55                         {
56                             radioButton1.Checked =
true;
57                         }
58                         
else
59                         {
60                             radioButton2.Checked =
true;
61                         }
62                         textBox3.Text = dr.GetValue(
2).ToString();
63                         textBox4.Text = dr.GetValue(
3).ToString();
64                         textBox5.Text = dr.GetValue(
4).ToString();
65                         textBox6.Text = dr.GetValue(
5).ToString();
66                         textBox7.Text = dr.GetValue(
6).ToString();
67                         textBox8.Text = dr.GetValue(
7).ToString();
68                         textBox10.Text = dr.GetValue(
8).ToString();
69                         textBox9.Text = dr.GetValue(
9).ToString();
70                         textBox11.Text = dr.GetValue(
10).ToString();
71                         textBox12.Text = dr.GetValue(
11).ToString();
72                         
73                     }
74                     
else
75                     {
76                         MessageBox.Show(
" Sorry, This ID, " + textBox1.Text + " Staff is not Available. ");
77                         textBox1.Text =
"";
78                     }
79                 }
80                 
catch (SqlException excep)
81                 {
82                     MessageBox.Show(excep.Message);
83                 }
84                 con.Close();
85             }
86         }
87
88         
private void button2_Click(object sender, EventArgs e)
89         {
90             SqlConnection con =
new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=F:\Sem.4\C# Projects\Trials\HospitalManagementSystemCSharp\HospitalManagementSystemCSharp\hospital.mdf;Integrated Security=True");
91             con.Open();
92             
string gen = string.Empty;
93             
if (radioButton1.Checked)
94             {
95                 gen =
"Male";
96             }
97             
else
98             {
99                 gen =
"Female";
100             }
101             
try
102             {
103                 
string str = " Update patient set name='" + textBox2.Text + "',gen='" + gen + "',age='" + textBox3.Text + "',date='" + textBox4.Text + "',cont='" + textBox5.Text + "',addr='" + textBox6.Text + "',disease='" + textBox7.Text + "',status='" + textBox8.Text + "',r_type='" + textBox10.Text + "',building='" + textBox9.Text + "',r_no='" + textBox11.Text + "',price='" + textBox12.Text + "' where id='" + textBox1.Text + "'";
104
105                 SqlCommand cmd =
new SqlCommand(str, con);
106                 cmd.ExecuteNonQuery();
107
108                 
string str1 = "select max(id) from patient;";
109
110                 SqlCommand cmd1 =
new SqlCommand(str1, con);
111                 SqlDataReader dr = cmd1.ExecuteReader();
112                 
if (dr.Read())
113                 {
114                     MessageBox.Show(
"" + textBox2.Text + "'s Details is Updated Successfully.. ", "Important Message");
115                     textBox2.Text =
"";
116                     textBox4.Text =
"";
117                     textBox5.Text =
"";
118                     textBox6.Text =
"";
119                     textBox7.Text =
"";
120                     
using (SqlConnection con1 = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=F:\Sem.4\C# Projects\Trials\HospitalManagementSystemCSharp\HospitalManagementSystemCSharp\hospital.mdf;Integrated Security=True"))
121                     {
122
123                         
string str2 = "SELECT * FROM patient";
124                         SqlCommand cmd2 =
new SqlCommand(str2, con1);
125                         SqlDataAdapter da =
new SqlDataAdapter(cmd2);
126                         DataTable dt =
new DataTable();
127                         da.Fill(dt);
128                         dataGridView1.DataSource =
new BindingSource(dt, null);
129                     }
130                 }
131             }
132             
catch (SqlException excep)
133             {
134                 MessageBox.Show(excep.Message);
135             }
136             con.Close();
137         }
138
139         
private void button3_Click(object sender, EventArgs e)
140         {
141             SqlConnection con =
new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=F:\Sem.4\C# Projects\Trials\HospitalManagementSystemCSharp\HospitalManagementSystemCSharp\hospital.mdf;Integrated Security=True");
142             con.Open();
143             
try
144             {
145
146                 
string str = "DELETE FROM patient WHERE id = '" + textBox1.Text + "'";
147
148                 SqlCommand cmd =
new SqlCommand(str, con);
149                 cmd.ExecuteNonQuery();
150                 con.Close();
151                 MessageBox.Show(
" Patient Record Delete Successfully");
152                 
using (con)
153                 {
154
155                     
string str2 = "SELECT * FROM patient";
156                     SqlCommand cmd2 =
new SqlCommand(str2, con);
157                     SqlDataAdapter da =
new SqlDataAdapter(cmd2);
158                     DataTable dt =
new DataTable();
159                     da.Fill(dt);
160
161                     dataGridView1.DataSource =
new BindingSource(dt, null);
162                 }
163                 textBox2.Text =
"";
164                 textBox3.Text =
"";
165                 textBox4.Text =
"";
166                 textBox5.Text =
"";
167                 textBox6.Text =
"";
168                 textBox7.Text =
"";
169                 textBox8.Text =
"";
170                 textBox9.Text =
"";
171                 textBox10.Text =
"";
172                 textBox11.Text =
"";
173             }
174
175             
catch (SqlException ex)
176             {
177                 MessageBox.Show(ex.Message);
178                 MessageBox.Show(
"Please Enter Patient Id..");
179             }
180         }
181     }
182     
183 }


TODO: This line of code loads data into the 'hospitalDataSet1.patient' table. You can move, or remove it, as needed.



Gõ tìm kiếm nhanh...